package com.code.util;

import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;

public class MapperUtil {
	
	public static Map<String, Object> packageUpdateDataByParam(Object setModule, Object whereModule) {
		Map<String, Object> map = new HashMap<String, Object>();

		try {
			BeanInfo beanInfo = Introspector.getBeanInfo(setModule.getClass());
			PropertyDescriptor[] pds = beanInfo.getPropertyDescriptors();
			for (PropertyDescriptor pd : pds) {
				Object value = pd.getReadMethod().invoke(setModule, new Object[]{});
				if (null != value) {
					map.put(pd.getName(), value);
				}
			}
			
			beanInfo = Introspector.getBeanInfo(whereModule.getClass());
			pds = beanInfo.getPropertyDescriptors();
			for (PropertyDescriptor pd : pds) {
				Object value = pd.getReadMethod().invoke(whereModule, new Object[]{});
				if (null != value) {
					map.put("where_" + pd.getName(), value);
				}
			}
		} catch (IntrospectionException e) {
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		}
		
		return map;
	}
	
	
}
